const http = require('http');
const request = require('request');

let server = http.createServer();

server.on('request',(req,res)=>{
  if(req.url.startsWith('/proxy')) {
    // 1:设置相应头
    res.setHeader('access-control-allow-origin','*');
    var x = request('http://localhost:8888/proxy')
    req.pipe(x);   // 页面请求.管道流给(x)
    x.pipe(res);   // x.管道流给(页面响应)
  }
});

server.listen(7777);